Developer Documentation

QuickTime 4 API Documentation

QuickTime 4 Reference

| Previous | Chapter Contents | Chapter Top | Next |

Reading Movie Data

Data handler components provide two basic read facilities. The DataHGetData function is a fully synchronous read operation, while the DataHScheduleData function is asynchronous. Applications provide scheduling information when they call your component's DataHScheduleData function. When your component processes the queued request, it calls the application's data-handler completion function (for more information, see "Completion Function" later in this chapter). By calling your component's DataHFinishData function, applications can force your component to process queued read requests. Applications may call your component's DataHGetScheduleAheadTime function in order to determine how far in advance your component prefers to get read requests.

Before any application can read data from a data reference, it must open read access to that reference by calling your component's DataHOpenForRead function. The DataHCloseForRead function closes that read access path.

For more information on reading movie data, see "Retrieving Movie Data" .

DataHOpenForRead

Your component opens its current data reference for read-only access.

pascal ComponentResult DataHOpenForRead (DataHandler dh);
dh
Identifies the calling program's connection to your data handler component.

DISCUSSION

After setting your component's current data reference by calling the DataHSetDataRef function, client programs call the DataHOpenForRead function in order to start reading from the data reference. Your component should open the data reference for read-only access. If the data reference is already open or cannot be opened, return an appropriate error code.

Note that the Movie Toolbox may try to read data from a data reference without calling your component's DataHOpenForRead function. If this happens, your component should open the data reference for read-only access, respond to the read request, and then leave the data reference open in anticipation of later read requests.

DataHCloseForRead

Your component closes read-only access to its data reference.

pascal ComponentResult DataHCloseForRead (DataHandler dh);
dh
Identifies the calling program's connection to your data handler component.

DISCUSSION

Note that a client program may close its connection to your component (by calling the Component Manager's CloseComponent function) without closing the read path. If this happens, your component should close the data reference before closing the connection.

RESULT CODES

dataNotOpenForRead
-2042 Data reference not open for read
dataAlreadyClosed
-2045 This reference already closed

DataHGetData

Your component reads data from its current data reference. This is a synchronous read operation.

pascal ComponentResult DataHGetData (
                     DataHandler dh,
                     Handle h,
                     long hOffset,
                     long offset,
                     long size);
dh
Identifies the calling program's connection to your data handler component.

h
Specifies the handle to receive the data.

hOffset
Identifies the offset into the handle where your component should return the data.

offset
Specifies the offset in the data reference from which your component is to read.

size
Specifies the number of bytes to read.

DISCUSSION

The DataHGetData function provides a high-level read interface. This is a synchronous read operation; that is, the client program's execution is blocked until your component returns control from this function. As a result, most time-critical clients use the DataHScheduleData function to read data.

Note that the Movie Toolbox may try to read data from a data reference without calling your component's DataHOpenForRead function. If this happens, your component should open the data reference for read-only access, respond to the read request, and then leave the data reference open in anticipation of later read requests.

SEE ALSO

Client programs can force your component to invalidate any cached data by calling your component's DataHFlushCache function.

DataHScheduleData

Your component reads data from its current data reference. This can be a synchronous read operation or an asynchronous read operation.

pascal ComponentResult DataHScheduleData (
                     DataHandler dh,
                     Ptr placeToPutDataPtr,
                     long fileOffset,
                     long dataSize,
                     long refCon,
                     DataHSchedulePtr scheduleRec,
                     DHCompletionUPP completionRtn);
dh
Identifies the calling program's connection to your data handler component.

placeToPutDataPtr
Specifies the location in memory that is to receive the data.

fileOffset
Specifies the offset in the data reference from which your component is to read.

dataSize
Specifies the number of bytes to read.

refCon
Contains a reference constant that your data handler component should provide to the data-handler completion function specified with the completionRtn parameter.

scheduleRec
Contains a pointer to a schedule record. If this parameter is set to nil , then the client program is requesting a synchronous read operation (that is, your data handler must return the data before returning control to the client program).

If this parameter is not set to nil , it must contain the location of a schedule record that has timing information for an asynchronous read request. Your data handler should return control to the client program immediately, and then call the client's data-handler completion function when the data is ready. The schedule record is described later in this section.

completionRtn
Contains a pointer to a data-handler completion function. When your data handler finishes with the client program's read request, your component must call this routine. Be sure to call this routine even if the request fails. Your component should pass the reference constant that the client program provided with the refCon parameter.

The client program must provide a completion routine for all asynchronous read requests (that is, all requests that include a valid schedule record). For synchronous requests, client programs should set this parameter to nil . However, if the function is provided, your handler must call it, even after synchronous requests.

DISCUSSION

The DataHScheduleData function provides both a synchronous and an asynchronous read interface. Synchronous read operations work like the DataHGetData function--the data handler component returns control to the client program only after it has serviced the read request. Asynchronous read operations allow client programs to schedule read requests in the context of a specified QuickTime time base. Your data handler queues the request and immediately returns control to the calling program. After your component actually reads the data, it calls the client program's data-handler completion function.

If your component cannot satisfy the request (for example, the request requires data more quickly than you can deliver it), your component should reject the request immediately, rather than queuing the request and then calling the client's data-handler completion function.

The client program provides scheduling information for scheduled reads in a schedule record. This structure is defined as follows:

typedef struct DataHScheduleRecord {
                    TimeRecord timeNeededBy; /* schedule info */
                    long     extendedID; /* type of data */
                    long     extendedVers; /* reserved */
                    Fixed   priority; /* priority */
                    } DataHScheduleRecord, *DataHSchedulePtr;
timeNeededBy
Specifies the time at which your data handler must deliver the requested data to the calling program. This time value is relative to the time base that is contained in this time record.

During pre-roll operations, the Movie Toolbox may use special values in certain time record fields. The time record fields in question are the scale and value fields. By correctly interpreting the values of these fields, your data handler can queue up the pre-roll read requests in the most efficient way for its device.

There are two types of pre-roll read operations. The first type is a required read; that is, the Movie Toolbox requires that the read operation be satisfied before the movie starts playing. The second type is an optional read. If your data handler can satisfy the read operation as part of the pre-roll operation, it should do so. Otherwise, your data handler may satisfy the request at a specified time while the movie is playing.

The Movie Toolbox indicates that a pre-roll read request is required by setting the scale field of the time record to -1. This literally means that the request is scheduled for a time that is infinitely far into the future. Your data handler should collect all such read requests, order them most efficiently for your device, and process them when the Movie Toolbox calls your component's DataHFinishData function.

For optional pre-roll read requests, the Movie Toolbox sets the scale field properly, but negates the contents of the value field. Your data handler has the option of delivering the data for this request with the required data, if that can be done efficiently. Otherwise, your data handler may deliver the data at its schedule time. You determine the scheduled time by negating the contents of the value field (that is, multiplying by -1).

For more information about pre-roll operations, see "Retrieving Movie Data," earlier in this chapter.

extendedID
Indicates the type of data that follows in the remainder of the record. The following values are valid:

kDataHExtendedSchedule
The remainder of the record contains extended scheduling information.

If the extendedID field is set to kDataHExtendedSchedule , the remainder of the schedule record is defined as follows:

extendedVers
Reserved; this field should always be set to 0.

priority
Indicates the relative importance of the data request. Client programs assign a value of 100.0 to data requests the must be delivered. Lower values indicate relatively less critical data. If your data handler must accommodate bandwidth limitations when delivering data, your component may use this value as an indication of which requests can be dropped with the least impact on the client program.

As an example, consider using priorities in a frame-differenced movie. Key frames might have priority values of 100.0, indicating that they are essential to proper playback. As you move through the frames following a key frame, each successive frame might have a lower priority value. Once you drop a frame, you must drop all successive frames of equal or lower priority until you reach another key frame, because each of these frames would rely on the dropped one for some image data.

Note that the Movie Toolbox may try to read data from a data reference without calling your component's DataHOpenForRead function. If this happens, your component should open the data reference for read-only access, respond to the read request, and then leave the data reference open in anticipation of later read requests.

SEE ALSO

Client programs can force your component to invalidate any cached data by calling your component's DataHFlushCache function.

DataHFinishData

The DataHFinishData function instructs your data handler component to complete or cancel one or more queued read requests. The client program would have issued those read requests by calling your component's DataHScheduleData function.

pascal ComponentResult DataHFinishData (
                     DataHandler dh,
                     Ptr placeToPutDataPtr,
                     Boolean cancel);
dh
Identifies the calling program's connection to your data handler component.

placeToPutDataPtr
Specifies the location in memory that is to receive the data. The value of this parameter identifies the specific read request to be completed. If this parameter is set to nil , the call affects all pending read requests.

cancel
Indicates whether the calling program wants to cancel the outstanding request. If this parameter is set to true , your data handler should cancel the request (or requests) identified by the placeToPutDataPtr parameter.

DISCUSSION

Client programs use the DataHFinishData function either to cancel outstanding read requests or to demand that the requests be serviced immediately. Pre-roll operations are a special case of the immediate service request. The client program will have queued one or more read requests with their scheduled time of delivery set infinitely far into the future. Your data handler queues those requests until the client program calls the DataHFinishData function demanding that all outstanding read requests be satisfied immediately.

Note that your component must call the client program's data-handler completion function for each queued request, even though the client program called the DataHFinishData function. Be sure to call the completion function for both canceled and completed read requests.

SEE ALSO

Client programs queue read requests by calling your component's DataHScheduleData function.

DataHGetScheduleAheadTime

The DataHGetScheduleAheadTime function allows your data-handler component to report how far in advance it prefers clients to issue read requests.

pascal ComponentResult DataHGetScheduleAheadTime (
                     DataHandler dh,
                     long *millisecs);
dh
Identifies the calling program's connection to your data handler component.

millisecs
Contains a pointer to a long. Your component should set this field with a value indicating the number of milliseconds you prefer to receive read requests in advance of the time when the data must be delivered.

DISCUSSION

This function allows your data handler to tell the client program how far in advance it should schedule its read requests. By default, the Movie Toolbox issues scheduled read requests between 1 and 2 seconds before it needs the data from those requests. For some data handlers, however, this may not be enough time. For example, some data handlers may have to accommodate network delays when processing read requests. Client programs that call this function may try to respect your component's preference.

Note, however, that not all client programs will call this function. Further, some clients may not be able to accommodate your preferred time in all cases, even if they have asked for your component's preference. As a result, your component should have a strategy for handling requests that do not provide enough advanced scheduling time. For example, if your component receives a DataHScheduleData request that it cannot satisfy, it can fail the request with an appropriate error code.

SEE ALSO

Client programs queue read requests by calling your component's DataHScheduleData function.


© 1999 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |